# -*- coding: utf-8 -*-
#
# Copyright (C) 2011  Benjamin Heil
#
# This file is part of Feedmail.
#
# Feedmail is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Django settings for feedmail project.

import os
import logging
import locale
import socket

SOCKET_TIMEOUT = 30.0
socket.setdefaulttimeout(SOCKET_TIMEOUT)

from revision import svnrev

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ENABLE_DEBUG_TOOLBAR = False

CURRENT_REVISION = svnrev()

# Title of this site
SITE_TITLE = 'Feedmail'

# Full name of this site
SITE_FULL_NAME = '%s (Rev %s)' % (SITE_TITLE, CURRENT_REVISION)

ADMINS = (
    ('Benjamin Heil', 'kontakt@bheil.net'),
)

MANAGERS = ADMINS

########################################################################
# USE "CREATE DATABASE <dbname> CHARACTER SET utf8;" TO CREATE THE DB! #
########################################################################
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'feedmail_dev', # Or path to database file if using sqlite3.
        'USER': 'feedmail_dev', # Not used with sqlite3.
        'PASSWORD': 'bAjGNT8W7DV5Oqwp', # Not used with sqlite3.
        'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '', # Set to empty string for default. Not used with sqlite3.
        'OPTIONS': {
            "init_command": "SET storage_engine=INNODB",
        },
    }
}

DEFAULT_CHARSET = 'utf-8'
TEST_CHARSET = 'utf-8'
TEST_COLLATION = 'utf8_general_ci'

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Europe/Berlin'

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'de-de'

DATE_FORMAT = '%d.%m.%Y'
TIME_FORMAT = '%H:%M:%S'
TIME_SHORT_FORMAT = '%H:%M'
DATETIME_SHORT_FORMAT = DATE_FORMAT + ' ' + TIME_SHORT_FORMAT
DATETIME_FORMAT = DATE_FORMAT + ' ' + TIME_FORMAT
# Alles auf Deutsch setzen, die gesamte Umgebung
LOCALE = 'de_DE.UTF-8'
locale.setlocale(locale.LC_ALL, LOCALE)

# All feed mails come from this address
DEFAULT_FROM_EMAIL = 'feedmail@bheil.net'

MAIL_STYLE_SHEET = 'h1{font-size:12pt;font-weight:bold;}body{font:11pt Ubuntu,Verdana,Arial;}a:link{color:#0066CC;}a:hover{color:#88BB22;}code{font-family:monospace;}blockquote,pre{border:1px solid #DADADA;background-color:#EEE;-moz-border-radius:4px;padding:8px;font-family:monospace;}#footer{margin-top:16px;padding:8px;-moz-border-radius:4px;background-color:#EEE;border:1px solid #DADADA;color:#444;}#feedmail-footer{float:right;font-size:xx-small;margin-bottom: 4px;color:#999;}#feedmail-footer a{color:#999;}'

# Alle server mails like broken links or status mails come from this account
SERVER_EMAIL = 'webmaster@bheil.net'

# Send status mail when 404
SEND_BROKEN_LINK_EMAILS = True

# Send status mails to managers when a new user registered or activated his account
SEND_REGISTER_STATUS_EMAILS = True

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = './media/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = 'http://127.0.0.1:8000/%s/media/' % (CURRENT_REVISION)

ADMIN_PREFIX = 'chef'

# Make this unique, and don't share it with anybody.
SECRET_KEY = '&dz30$wod^2rk51(qoc%5b*@q9cdn(#t7be%1yj#c1ee)fn6m2'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'feedmail.urls'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    './templates',
)

# Split Django Apps and local apps. This way we can only run our own tests
# with 'manage.py test' and not all django test cases
# http://groups.google.com/group/django-developers/msg/ec7508651e9e9fb8?pli=1
FEEDMAIL_APPS = (
    'base',
    'account',
    'feedmanager',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
) + FEEDMAIL_APPS

#TEST_RUNNER = 'local_tests.run_tests'
TEST_RUNNER = 'local_tests.FeedMailTestSuiteRunner'

CACHES = {
    'default': {
        # If you want to use Memcache, comment this line out and enable Memcached-Backend below
        'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
        #'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',        
        #'LOCATION': '127.0.0.1:11211',
        #'TIMEOUT': 35 * 60, # since the cron job should run every 30 min, make this a little bit larger
        #'OPTIONS': {
        #   'KEY_PREFIX': 'feedmail-udh2386dh3',
        #   'MAX_ENTRIES': 1000,
        #}
    }
}

# Root URL mit abschliessendem Slash
ROOT_URL = 'http://127.0.0.1:8000/'

# Root URL ohne abschliessendem Slash
ROOT_URL_WO_SLASH = ROOT_URL[:len(ROOT_URL) - 1]

# If you want to change this URLs you also have to modify urls.py
LOGIN_REDIRECT_URL = ROOT_URL
LOGIN_URL = '/account/login.html'
LOGOUT_URL = '/account/logout.html'

EMAIL_SUBJECT_PREFIX = ''

FEEDPARSER_USER_AGENT = '%s/%s +%s' % (SITE_TITLE, CURRENT_REVISION, ROOT_URL)

# Extending Django's user profile with our own account information
AUTH_PROFILE_MODULE = 'account.AccountProfile'

# The user has x hours to activate the new account
ACCOUNT_HOURS_TO_ACTIVATE = 48

# If false the user can't remove his own account
ACCOUNT_CAN_DELETE = True

CRON_LOG_LEVEL = logging.DEBUG
CRON_LOG_FILE = './cron/feedmail.log'
CRON_SEND_EXCEPTION_MAILS = True

# Send a warning mail to admins if cron jobs takes longer than X minutes
CRON_SEND_WARNING_AFTER_MIN = 20

ROBOTS_TXT = """User-agent: *
"""

# Use Unicode characters instead of their ascii psuedo-replacements
TEXTMODE_UNICODE_SNOB = 1

# Put the links after each paragraph instead of at the end.
TEXTMODE_LINKS_EACH_PARAGRAPH = 0

# Wrap long lines at position. 0 for no wrapping. (Requires Python 2.3.)
TEXTMODE_BODY_WIDTH = 78

# Formats of date & times when shown in page (e.g. on Errorlog-page)
DATE_FORMAT = '%d.%m.%Y'
TIME_FORMAT = '%H:%M:%S'
TIME_SHORT_FORMAT = '%H:%M'
DATETIME_SHORT_FORMAT = DATE_FORMAT + ' ' + TIME_SHORT_FORMAT
DATETIME_FORMAT = DATE_FORMAT + ' ' + TIME_FORMAT

# How much items per page? (on e.g. Errorlog-page)
PAGINATION_ITEMS_PER_PAGE = 25

# entries in FeedError table, which are older than this number of weeks, will be
# deleted during cron job
FEEDERROR_WEEKS = 4

# When running the test suite this feed will be fetched for some tests
# You can change it to a local feed or a feed in your network to speed up things
# It should be a valid feed!
TEST_FEED_URL = 'https://www.bheil.net/blog/rss.xml'
